import 'package:flutter/material.dart';

class AnimatedPositionedDemo extends StatefulWidget {
  @override
  _AnimatedPositionedDemoState createState() => _AnimatedPositionedDemoState();
}

class _AnimatedPositionedDemoState extends State<AnimatedPositionedDemo> {
  var _top = 30.0;
  @override
  Widget build(BuildContext context) {
    return Stack(
      // alignment: Alignment.center,
      // children: <Widget>[
      //   AnimatedPositioned(
      //     top: _top,
      //     duration: Duration(seconds: 2),
      //     child: Container(height: 50, width: 50, color: Colors.red),
      //   )
      // ],
      alignment: Alignment.center,
      children: [
        AnimatedPositioned(
            onEnd: () {
              print('end');
            },
            top: _top,
            child: Container(height: 50, width: 50, color: Colors.red),
            duration: Duration(seconds: 2)),
        RaisedButton(onPressed: () {
          setState(() {
            if (_top == 180) {
              _top = 30;
            } else {
              _top = 180;
            }
          });
        })
      ],
    );
  }
}
